﻿/*
Copyright (c) 2008 Martin Legris

Permission is hereby granted, free of charge, to any person obtaining a copy of this 
software and associated documentation files (the "Software"), to deal in the Software 
without restriction, including without limitation the rights to use, copy, modify, 
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the following 
conditions:

The above copyright notice and this permission notice shall be included in all copies 
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ignore
*/
package newcommerce.lastfm.api.data 
{
	import newcommerce.lastfm.api.feeds.LFMImageFeed;
	import newcommerce.lastfm.api.feeds.LFMSimilarArtistFeed;
	
	/**
	 * Data structure containing all information returned by the artist.getInfo API method
	 * @author Martin Legris ( http://blog.martinlegris.com )
	 */
	
	public class LFMArtistInfo 
	{
		protected var _name:String;
		protected var _mbid:String;
		protected var _url:String;
		protected var _listeners:Number;
		protected var _playCount:Number;
		protected var _streamable:Boolean;
		
		protected var _images:LFMImageFeed;
		protected var _similar:LFMSimilarArtistFeed;
		protected var _bio:LFMBioData;
		
		/**
		 * The name of the artist
		 */
		public function get name():String { return _name; }
		
		/**
		 * The Music Brainz Id for ths artist
		 */
		public function get mbid():String { return _mbid; }
		
		/**
		 * The URL of the artist on the LastFM website
		 */
		public function get url():String { return _url; }
		
		/**
		 * The amount of people who listened to this artist as recorded by LastFM Scrobbling
		 */		
		public function get listeners():Number { return _listeners; }
		
		/**
		 * Not sure.. this is probably used internally by LastFM
		 */
		public function get streamable():Boolean { return _streamable; }
		
		/**
		 * The amount of times this artist was played, as recorded by LastFM Scrobbling
		 */
		public function get playCount():Number { return _playCount; }
		
		/**
		 * The image feed (small, medium, big) for this artist
		 */		
		public function get images():LFMImageFeed { return _images; }
		
		/** 
		 * A feed containing similar artists
		 */
		public function get similar():LFMSimilarArtistFeed { return _similar; }		
		
		/**
		 * The bio data structure for this artist
		 */
		public function get bio():LFMBioData { return _bio; }
		
		public function LFMArtistInfo() 
		{
			
		}
		
		/**
		 * A function that converts LastFM's XML structure into LFMArtistInfo data object for easier manipulation
		 * @param	xml the XML structure returned by the api method artist.getInfo
		 * @return LFMArtistInfo data object
		 */
		public static function fromXML(xml:XML):LFMArtistInfo
		{
			var data:LFMArtistInfo = new LFMArtistInfo();
			data._name = xml.name.toString();
			data._mbid = xml.mbid.toString();
			data._url = xml.url.toString();
			data._images = new LFMImageFeed(xml.image);
			data._streamable = (xml.streamable.toString() == "1");
			data._playCount = parseInt(xml.stats[0].playcount.toString());
			data._listeners = parseInt(xml.stats[0].listeners.toString());
			data._similar = new LFMSimilarArtistFeed(xml.similar[0], xml.name.toString());
			data._bio = LFMBioData.fromXML(xml.bio[0]);

			return data;
		}
	}
}